Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added github action for Check for embedded CSS and the correct stylesheet in Typescript files #2907 #3041

Conversation

IITI-tushar
Copy link
Contributor

@IITI-tushar IITI-tushar commented Dec 29, 2024

What kind of change does this PR introduce?
feature

Issue Number:
#2907

Fixes #2907

Did you add tests for your changes?

Snapshots/Videos:
I checked if the script is working as expected or not.
The screen shots are here..

image

image

image

image

If relevant, did you update the documentation?

Summary

Does this PR introduce a breaking change?
maybe

Other information

Have you read the contributing guide?

yes

Summary by CodeRabbit

  • New Features

    • Added a Python script to check for CSS violations in TypeScript files.
    • Integrated CSS violation check into GitHub Actions workflow.
  • Chores

    • Created a new GitHub Actions workflow step to run CSS violation checks and report results.

Copy link
Contributor

coderabbitai bot commented Dec 29, 2024

Walkthrough

A new Python script .github/workflows/css_check.py has been developed to check TypeScript files for CSS violations and embedded CSS. The script includes functions to traverse directories, identify embedded CSS patterns, and validate CSS imports. It is designed to be run as part of GitHub Actions, with the ability to check files against specific CSS-related criteria. The script is added to the GitHub workflow configuration in .github/workflows/pull-request.yml to be executed during the code quality checks.

Changes

File Change Summary
.github/workflows/css_check.py Added new Python script with functions: check_embedded_css(), check_files(), and main() to validate CSS imports and detect embedded CSS in TypeScript files
.github/workflows/pull-request.yml Added a new step to run the CSS check script as part of the Code-Quality-Checks job

Assessment against linked issues

Objective Addressed Explanation
Check for embedded CSS violations [#2907]
Only reference src/style/app.module.css [#2907] Partial implementation needs verification.
CLI option with --directory flag [#2907]
Exclude unit test files [#2907] Needs explicit confirmation.
Python3 with linting standards [#2907] Requires detailed code review.

Possibly related PRs

Suggested labels

ignore-sensitive-files-pr

Suggested reviewers

  • palisadoes
  • rishav-jha-mech
  • GlenDsza

Poem

🐰 In the realm of code, a script takes flight,
Hunting CSS with algorithmic might,
No embedded styles shall escape its gaze,
Keeping our codebase in pristine arrays!
A rabbit's vigilance, sharp and bright! 🕵️‍♀️


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2cdc7e0 and 2218e9f.

📒 Files selected for processing (1)
  • .github/workflows/pull-request.yml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/pull-request.yml
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyse Code With CodeQL (javascript)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@IITI-tushar IITI-tushar force-pushed the added-add.module.css-check-python-script branch from 66d0d88 to acdd27a Compare December 29, 2024 12:38
Copy link

Our Pull Request Approval Process

Thanks for contributing!

Testing Your Code

Remember, your PRs won't be reviewed until these criteria are met:

  1. We don't merge PRs with poor code quality.
    1. Follow coding best practices such that CodeRabbit.ai approves your PR.
  2. We don't merge PRs with failed tests.
    1. When tests fail, click on the Details link to learn more.
    2. Write sufficient tests for your changes (CodeCov Patch Test). Your testing level must be better than the target threshold of the repository
    3. Tests may fail if you edit sensitive files. Ask to add the ignore-sensitive-files-pr label if the edits are necessary.
  3. We cannot merge PRs with conflicting files. These must be fixed.

Our policies make our code better.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
.github/workflows/css_check.py (2)

9-20: Expand Embedded CSS Detection Beyond Hex Codes

Right now, check_embedded_css only catches inline hex color usage (e.g., #FFF, #FFFFFF). If there are other forms of embedded styling (e.g., style attributes, inlined multi-line CSS, single-line style properties), they will remain undetected.

You might consider broadening the regex pattern or introducing multiple detection rules to cover other CSS constructs inlined in TypeScript files.


23-74: Enhance CSS Import Handling & Validation

  1. Currently, the check for valid CSS imports is limited to endings with /app.module.css. You may want to allow for multiple valid module file names, for instance app.module.css or styles.module.css, based on your project guidelines or common naming conventions.

  2. Consider whether you need to detect imports for .less, .scss, or .sass if the project supports them.

If the repository might evolve to use or allow multiple .module.* variations, you can update the condition to allow them or make it configurable.

.github/workflows/pull-request.yml (1)

42-42: Remove Trailing Whitespace

The lines added/modified at 42, 46, and 47 contain trailing spaces, as flagged by yamllint. Removing trailing whitespace will help maintain a clean and consistent YAML file.

Apply this diff:

42-      
42+
46-          
46+
47-          
47+

Also applies to: 46-46, 47-47

🧰 Tools
🪛 yamllint (1.35.1)

[error] 42-42: trailing spaces

(trailing-spaces)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f4830d0 and acdd27a.

📒 Files selected for processing (2)
  • .github/workflows/css_check.py (1 hunks)
  • .github/workflows/pull-request.yml (1 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
.github/workflows/pull-request.yml

[error] 42-42: trailing spaces

(trailing-spaces)


[error] 46-46: trailing spaces

(trailing-spaces)


[error] 47-47: trailing spaces

(trailing-spaces)

🔇 Additional comments (2)
.github/workflows/css_check.py (2)

1-2: File-level Documentation is Clear

Your module-level docstring concisely explains the purpose of the script. This is a great start for developers browsing the file.


77-116: Verify Edge Cases and Add Automated Tests

Your main() function, CLI argument parsing, and overall structure are concise. However:

  • No mention of test coverage or unit tests for these checks.
  • Edge case: Large directories, symlinks, or files with unusual text encoding might pose unexpected issues.

As a follow-up, consider adding a test suite or coverage checks to verify the script’s behavior under various scenarios (e.g., large file sets, unusual file encodings, different CSS naming conventions).

coderabbitai[bot]
coderabbitai bot previously approved these changes Dec 29, 2024
@palisadoes palisadoes changed the title feat: added github action for Check for embedded CSS and the correct stylesheet in Typescript files issue#2907 feat: added github action for Check for embedded CSS and the correct stylesheet in Typescript files #2907 Dec 29, 2024
Copy link
Member

@noman2002 noman2002 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the conflicting files.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (2)
.github/workflows/css_check.py (2)

58-58: Make test file exclusion configurable

The hardcoded exclusion of test files reduces flexibility.

Consider making test file exclusion configurable through command-line arguments:

-            if file.endswith((".ts", ".tsx")) and "test" not in root:
+            if file.endswith((".ts", ".tsx")) and not any(exclude in root for exclude in test_excludes):

Add to the argument parser:

parser.add_argument(
    "--test_excludes",
    nargs="*",
    default=["test", "__tests__"],
    help="Patterns to identify test directories"
)

99-117: Enhance error reporting and output format

The current output format could be improved for better integration with CI tools.

Consider adding:

  1. JSON output format option
  2. More detailed error statistics
  3. Colored output for better readability
+    parser.add_argument(
+        "--output-format",
+        choices=["text", "json"],
+        default="text",
+        help="Output format (text or json)"
+    )

+    if args.output_format == "json":
+        import json
+        result = {
+            "violations": violations,
+            "embedded_css": embedded_css_violations,
+            "correct_imports": correct_css_imports,
+            "statistics": {
+                "files_checked": files_checked,
+                "violations_count": len(violations),
+                "embedded_css_count": len(embedded_css_violations)
+            }
+        }
+        print(json.dumps(result, indent=2))
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between acdd27a and 4ea8e30.

📒 Files selected for processing (2)
  • .github/workflows/css_check.py (1 hunks)
  • .github/workflows/pull-request.yml (1 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
.github/workflows/pull-request.yml

[error] 42-42: trailing spaces

(trailing-spaces)


[error] 46-46: trailing spaces

(trailing-spaces)


[error] 47-47: trailing spaces

(trailing-spaces)


[error] 48-48: trailing spaces

(trailing-spaces)


[error] 49-49: syntax error: expected , but found ''

(syntax)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyse Code With CodeQL (javascript)

.github/workflows/css_check.py Outdated Show resolved Hide resolved
.github/workflows/css_check.py Outdated Show resolved Hide resolved
.github/workflows/css_check.py Outdated Show resolved Hide resolved
.github/workflows/pull-request.yml Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
.github/workflows/css_check.py (2)

11-23: Improve hex color code pattern matching

The pattern might match hex codes in comments or strings, leading to false positives.

Consider updating the pattern to exclude matches in comments and strings:

-    embedded_css_pattern = r"#([0-9a-fA-F]{3}){1,2}"  # Matches CSS color codes
+    # Exclude matches in single-line comments, multi-line comments, and strings
+    embedded_css_pattern = r'(?<!\/\/[^\n]*?)(?<!\/\*[\s\S]*?)(?<![\'"`])#([0-9a-fA-F]{3}){1,2}(?![0-9a-fA-F])'

70-72: Improve CSS import pattern matching

The current pattern might miss some valid import statements.

Consider updating the pattern to handle more import variations:

-                    r'import\s+.*?["\'](.*?\.css)["\'];', content
+                    r'import\s+(?:(?:{[^}]*}|\*|\w+)\s+from\s+)?["\'](.*?\.css)["\'];', content
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4ea8e30 and 2cdc7e0.

📒 Files selected for processing (1)
  • .github/workflows/css_check.py (1 hunks)
🧰 Additional context used
📓 Learnings (1)
.github/workflows/css_check.py (1)
Learnt from: IITI-tushar
PR: PalisadoesFoundation/talawa-admin#3041
File: .github/workflows/css_check.py:11-22
Timestamp: 2025-01-07T09:50:29.019Z
Learning: In the talawa-admin project, CSS validation in TypeScript files should only check for hex color codes using the pattern `#([0-9a-fA-F]{3}){1,2}` and ensure that files only reference the `src/style/app.module.css` stylesheet.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyse Code With CodeQL (javascript)
🔇 Additional comments (2)
.github/workflows/css_check.py (2)

1-9: LGTM! Well-structured script setup.

The script has proper shebang, encoding declaration, and imports.


148-150: LGTM! Proper script entry point.

The script uses the standard Python idiom for execution.

.github/workflows/css_check.py Show resolved Hide resolved
.github/workflows/css_check.py Show resolved Hide resolved
@IITI-tushar IITI-tushar requested a review from noman2002 January 7, 2025 10:17
Copy link
Member

@noman2002 noman2002 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants